<?
include "include/config.php";

$user_mod_query=mysql_query("select id,name from users where level=10 ");
$agents["0"]="Alegeti agent";	
while ($users=mysql_fetch_array($user_mod_query)) {
    $agents[$users["id"]] =$users["name"];
}
$smarty->assign('agent',$agents);  
 
 
$tip=array ('1'=>'Garsoniera','2'=>'Apartament 2 camere','3'=>'Apartament 3 camere','4'=>'Apartament 4 camere','5'=>'Teren','6'=>'Spatiu Comercial','7'=>'Casa/Vila');
$oferta=array ('1'=>'Vanzare','2'=>'Inchiriere');
$tip=array ('0'=>'Toate mesajele','1'=>'Caut sa inchiriez','2'=>'Caut sa cumpar','3'=>'Ofer spre inchiriere','4'=>'Ofer spre vanzare','5'=>'Dosar');

$smarty->assign('tip',$tip);
$smarty->assign('oferta',$oferta);

    
if ($_POST['trimite']!='') 
{     
      $N = addslashes($_REQUEST["Nume"]);
	  $T = addslashes($_REQUEST["Telefon"]);
	  $M = addslashes($_REQUEST["mesaj"]); 
	  $YM = addslashes($_REQUEST["Email"]);
			
if (strlen($N)>3) $bineN = 1 ; else {$bineN=0; $eroare="Completati Numele";}
if ((isset($T)) AND (is_numeric($T))) $bineT = 1 ; else  {$bineT=0;	 $eroare="Completati Numarul de Telefonul";}
if (strlen($M)>3) $bineM = 1 ; else  { $bineM=0; $eroare="Completati Casuta de Mesaje";}	
	
	$smarty->assign ('eroare',$eroare);
 $rezultat = $bineN*$bineT*$bineM; 
 
    $errors=0;
    
    $number = $_POST['number'];
    if(md5($number) != $_SESSION['image_value'])
    $eroare= 'Cod gresit !';
    
     
 if (($rezultat==1) AND ($eroare==''))
	{ 	

	$introdu = " <strong>Nume :</strong>".$N." <strong>Telefon : </strong> ".$T." <strong><br>Mesaj : </strong>".$M." <strong> <br> Email : </strong>".$YM; 
    
 
	mysql_query( "INSERT INTO mesaje ( nume ,descriere, data,telefon ,email,comentarii,mesaj) VALUES ('".$N."', '".$introdu."',date(NOW()),'".$T."','".$YM."','','".$M."')" ) ;
	$smarty->assign ('trimis',1);
	}
	//se creeaza un e-mail de alerta si se trimit datele. 
		$to ="office@timonatrust.ro" . " ,";
		$to .="dan@timonatrust.ro";
       
		$subiect = "CONTACT!";
		$mesaj= '<html>
					<head><title>Contact!</title></head>
				<body>
                    <b><font color="#333333" face="tahoma">'.$tip[$Tranz] . ' ' . $Ofert.'</font><b><br><br>
					<font color="#999900">'.$introdu.'</font><br><br><br><br>
					<div align="center">This is a message from http://www.timona.ro</div>
				</body>					
				</html>';
		$headers = "MIME-Version: 1.0\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' ."r\n";
		$headers .= "From: ".$N." <".$YM.">\n";
		@mail($to, $subiect, $mesaj, $headers);

}

$smarty->assign ('eroare',$eroare);    
$smarty->assign("content", $smarty->fetch(tmpd.'contact'.tmpl_ext));
include "include/make_page.php";
?>
